//
//  OfflineHapkidoPresController.swift
//  I.S.A.P WT
//
//  Created by Илья Проскурнев on 24.05.2021.
//  Copyright © 2021 Илья Проскурнев. All rights reserved.
//

import Foundation
import UIKit

class OfflineHapkidoPresController : UIViewController, UINavigationControllerDelegate, RadioButtonFreestylePres1Delegate, RadioButtonFreestylePres2Delegate, RadioButtonFreestylePres3Delegate, RadioButtonFreestylePres4Delegate {
    
    @IBOutlet weak var accyracy: UILabel!
    @IBOutlet weak var presentation: UILabel!
    @IBOutlet weak var total: UILabel!
    
    @IBOutlet weak var send: UIButton!
    
    var radioButtonFreestylePres1: RadioButtonFreestylePres1?
    var radioButtonFreestylePres2: RadioButtonFreestylePres2?
    var radioButtonFreestylePres3: RadioButtonFreestylePres3?
    var radioButtonFreestylePres4: RadioButtonFreestylePres4?
    
    var Acd: Double!
    var num01: Int!
    var num03: Int!
    var freestyle: Int!
    
    var pr1 = 0
    var pr2 = 0
    var pr3 = 0
    var pr4 = 0
    
    @IBOutlet weak var creativity: UILabel!
    @IBOutlet weak var harmony: UILabel!
    @IBOutlet weak var energy: UILabel!
    @IBOutlet weak var choreography: UILabel!
    
    @IBOutlet weak var creativity10: UIButton!
    @IBOutlet weak var creativity09: UIButton!
    @IBOutlet weak var creativity08: UIButton!
    @IBOutlet weak var creativity07: UIButton!
    @IBOutlet weak var creativity06: UIButton!
    @IBOutlet weak var creativity05: UIButton!
    @IBOutlet weak var creativity04: UIButton!
    @IBOutlet weak var creativity03: UIButton!
    @IBOutlet weak var creativity02: UIButton!
    @IBOutlet weak var creativity01: UIButton!
    @IBOutlet weak var creativity00: UIButton!
    
    @IBOutlet weak var harmony10: UIButton!
    @IBOutlet weak var harmony09: UIButton!
    @IBOutlet weak var harmony08: UIButton!
    @IBOutlet weak var harmony07: UIButton!
    @IBOutlet weak var harmony06: UIButton!
    @IBOutlet weak var harmony05: UIButton!
    @IBOutlet weak var harmony04: UIButton!
    @IBOutlet weak var harmony03: UIButton!
    @IBOutlet weak var harmony02: UIButton!
    @IBOutlet weak var harmony01: UIButton!
    @IBOutlet weak var harmony00: UIButton!
    
    @IBOutlet weak var energy10: UIButton!
    @IBOutlet weak var energy09: UIButton!
    @IBOutlet weak var energy08: UIButton!
    @IBOutlet weak var energy07: UIButton!
    @IBOutlet weak var energy06: UIButton!
    @IBOutlet weak var energy05: UIButton!
    @IBOutlet weak var energy04: UIButton!
    @IBOutlet weak var energy03: UIButton!
    @IBOutlet weak var energy02: UIButton!
    @IBOutlet weak var energy01: UIButton!
    @IBOutlet weak var energy00: UIButton!

    @IBOutlet weak var choreography10: UIButton!
    @IBOutlet weak var choreography09: UIButton!
    @IBOutlet weak var choreography08: UIButton!
    @IBOutlet weak var choreography07: UIButton!
    @IBOutlet weak var choreography06: UIButton!
    @IBOutlet weak var choreography05: UIButton!
    @IBOutlet weak var choreography04: UIButton!
    @IBOutlet weak var choreography03: UIButton!
    @IBOutlet weak var choreography02: UIButton!
    @IBOutlet weak var choreography01: UIButton!
    @IBOutlet weak var choreography00: UIButton!
    
    func radioButtonPres1SelectButton(selectedButton: UIButton?) {
        creativity.text = selectedButton?.currentTitle
        pr1 = Int(Double(selectedButton?.currentTitle ?? "0.0")!*10)
        printScoring()
    }
    
    func radioButtonPres2SelectButton(selectedButton: UIButton?) {
        harmony.text = selectedButton?.currentTitle
        pr2 = Int(Double(selectedButton?.currentTitle ?? "0.0")!*10)
        printScoring()
    }
    
    func radioButtonPres3SelectButton(selectedButton: UIButton?) {
        energy.text = selectedButton?.currentTitle
        pr3 = Int(Double(selectedButton?.currentTitle ?? "0.0")!*10)
        printScoring()
    }
    
    func radioButtonPres4SelectButton(selectedButton: UIButton?) {
        choreography.text = selectedButton?.currentTitle
        pr4 = Int(Double(selectedButton?.currentTitle ?? "0.0")!*10)
        printScoring()
    }
    
    func printScoring() {
        
        creativity.text = String(Double(pr1)/Double(10))
        harmony.text = String(Double(pr2)/Double(10))
        energy.text = String(Double(pr3)/Double(10))
        choreography.text = String(Double(pr4)/Double(10))
        let sc = String(Double(Acd))
        let ac = Int(Acd*10)
        accyracy.text = sc
        presentation.text = String(Double(pr1+pr2+pr3+pr4)/Double(10))
        total.text = String(Double(pr1+pr2+pr3+pr4+ac)/Double(10))
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        radioButtonFreestylePres1 = RadioButtonFreestylePres1(buttons: creativity10, creativity09, creativity08, creativity07, creativity06, creativity05, creativity04, creativity03, creativity02, creativity01, creativity00)
        radioButtonFreestylePres1!.delegate = self
        radioButtonFreestylePres1!.shouldLetDeSelect = true
        
        radioButtonFreestylePres2 = RadioButtonFreestylePres2(buttons: harmony10, harmony09, harmony08, harmony07, harmony06, harmony05, harmony04, harmony03, harmony02, harmony01, harmony00)
        radioButtonFreestylePres2!.delegate = self
        radioButtonFreestylePres2!.shouldLetDeSelect = true
        
        radioButtonFreestylePres3 = RadioButtonFreestylePres3(buttons: energy10, energy09, energy08, energy07, energy06, energy05, energy04, energy03, energy02, energy01, energy00)
        radioButtonFreestylePres3!.delegate = self
        radioButtonFreestylePres3!.shouldLetDeSelect = true
        
        radioButtonFreestylePres4 = RadioButtonFreestylePres4(buttons: choreography10, choreography09, choreography08, choreography07, choreography06, choreography05, choreography04, choreography03, choreography02, choreography01, choreography00)
        radioButtonFreestylePres4!.delegate = self
        radioButtonFreestylePres4!.shouldLetDeSelect = true
        
        
        printScoring()
    }
    
    override func prepare (for segue: UIStoryboardSegue, sender: Any?) {
        let frestylePresentationController: OfflineHapkidoController = segue.destination as! OfflineHapkidoController

        frestylePresentationController.freestyle = self.freestyle
    }
    
}

